package com.loren.demo07.cluster.config;

import com.loren.demo07.cluster.websocket.handler.CustomClusterMessageHandler;
import com.loren.demo07.cluster.websocket.interceptor.CustomClusterHandshakeInterceptor;
import lombok.AllArgsConstructor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.socket.config.annotation.EnableWebSocket;
import org.springframework.web.socket.config.annotation.WebSocketConfigurer;
import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry;

@Configuration
@EnableWebSocket
@AllArgsConstructor
public class ClusterConfig implements WebSocketConfigurer {

    private final CustomClusterMessageHandler customClusterMessageHandler;

    private final CustomClusterHandshakeInterceptor customClusterHandshakeInterceptor;

    @Override
    public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
        registry.addHandler(this.customClusterMessageHandler, "/cluster/websocket").addInterceptors(this.customClusterHandshakeInterceptor);
    }
}